﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PhotoGallery.Infrastructure.Roots.Configuration;
using System.Linq;
using System.Configuration;
using System.IO;
namespace PhotoGallery.Infrastructure
{
    public class FileConfiguration
    {
        /// <summary>
        /// 相对路径
        /// </summary>
        public static string Path { get; protected set; }

        /// <summary>
        /// 绝对路径
        /// </summary>
        public static string FullPath { get; protected set; }

        /// <summary>
        /// 文件目录
        /// </summary>
        public static DirectoryInfo Roots { get; protected set; }

        /// <summary>
        /// 临时文件
        /// </summary>
        public static string TmpPath { get; protected set; }

        /// <summary>
        /// 临时绝对路径
        /// </summary>
        public static string TmpFullPath { get; protected set; }

        /// <summary>
        /// 临时目录
        /// </summary>
        public static DirectoryInfo TmpRoots { get; protected set; }

        public static string DefaultImgPath { get; protected set; }

        static FileConfiguration()
        {
            RootSettings rootsSettings = (RootSettings)ConfigurationManager.GetSection(RootConstans.RootsConfigurationSectionName);
            if (rootsSettings == null || rootsSettings.Roots.Count == 0)
            {
                throw new InvalidProgramException("系统文件目录为空，请做好配置工作再开始！");
            }

            string appPath = CY.Utility.Common.RequestUtility.CurPhysicalApplicationPath;

            Path = rootsSettings.Roots["Root"].Value;



            FullPath = appPath + Path;

            Roots = new DirectoryInfo(FullPath);

            if (!Roots.Exists)
            {
                Roots.Create();
            }


            TmpPath = rootsSettings.Roots["Temp"].Value;

            TmpFullPath = appPath + TmpPath;

            TmpRoots = new DirectoryInfo(TmpFullPath);

            if (!TmpRoots.Exists)
                TmpRoots.Create();

            DefaultImgPath = appPath + rootsSettings.Roots["Default"].Value;
        }

        public FileConfiguration()
        {
            //do nothing temp
        }


    }
}
